import { Color } from "cc";
import { BuffData } from "../../../new/buff/const/BuffData";
import { BuffConfig, IBuffConfig } from "../../../new/buff/data/BuffConfig";
import { EventId } from "../../../new/event/EventId";
import EventMgr from "../../../new/event/EventMgr";
import { BuffDamageResult } from "../../../new/trigger/const/ITriggerResult";
import { BattleRoleUI } from "../../roleUI/BattleRoleUI";
import { ActionBase } from "./ActionBase";

/**
 * 行动-受到buff伤害
 */
export class BuffDamageAction extends ActionBase {
    targetUI: BattleRoleUI;
    result: BuffDamageResult
    constructor(targetUI: BattleRoleUI, result: BuffDamageResult) {
        super()
        this.targetUI = targetUI;
        this.result = result;
    }

    excute(): void {

        let damage = this.result.damage;
        this.targetUI.onBleed();
        this.targetUI.updateHp(-damage);
        let buffId = this.result.buffId;
        let buffCfg: IBuffConfig = BuffConfig.BuffConfi[buffId];
        let buffName = buffCfg.buffName;
        //飘字
        EventMgr.ins.event(EventId.FLOAT_TXT, { targetUI: this.targetUI, txt: `${buffName}:${this.result.damage}`, color: Color.RED });
    }
}